package com.doingnow.zuul.common;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.util.Arrays;
import java.util.List;

/**
 * 返回实体
 */
@Data
class ResponseError {

    private Long timestamp;
    private Integer status;
    private String error;
    private String message;
    private String path;
    private String exception;
    private List<String> errors;


    ResponseError(Integer status, HttpStatus httpStatus, String message, String path, String exception, List<String> errors) {
        super();
        this.timestamp = System.currentTimeMillis();
        this.status = status;
        this.error = httpStatus.name();
        this.message = message;
        this.path = path;
        this.exception = exception;
        this.errors = errors;
    }

    ResponseError(Integer status, HttpStatus httpStatus, String message, String path, String exception, String error) {
        super();
        this.timestamp = System.currentTimeMillis();
        this.status = status;
        this.error = httpStatus.name();
        this.message = message;
        this.path = path;
        this.exception = exception;
        errors = Arrays.asList(error);
    }

    public String toJsonString() {
        return JSON.toJSONString(this);
    }
}